package com.linkoog.devtools.code_generator;

import com.linkoog.devtools.code_generator.database.domain.DbType;
import com.linkoog.devtools.code_generator.database.domain.TypeMapping;
import com.linkoog.devtools.code_generator.template.loader.TemplateResourceLoader;
import com.linkoog.devtools.code_generator.template.model.node.TemplateNodeData;
import com.linkoog.devtools.code_generator.template.render.engine.TemplateType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class CodeGenConstants {



    public static List<TemplateNodeData> getDefaultTemplates(){
        List<TemplateNodeData> defaultTemplates = new ArrayList<>();
        //defaultTemplates.add(TemplateResourceLoader.loadTemplate(TemplateType.VELOCITY, "empty", "classpath:/templates/empty.zip"));
        //defaultTemplates.add(TemplateResourceLoader.loadTemplate(TemplateType.VELOCITY, "jeecgboot", "classpath:/templates/jeecgboot.zip"));
        //defaultTemplates.add(TemplateResourceLoader.loadTemplate(TemplateType.VELOCITY, "freemarker", "classpath:/templates/freemarker"));
        defaultTemplates.add(TemplateResourceLoader.loadTemplate(TemplateType.JTPL, "aiotagro-test", "classpath:/templates/aiotagro-test"));



        return defaultTemplates.stream().filter(Objects::nonNull).collect(Collectors.toList());
    }

    public static List<String> getDefaultColumnNameList(){
        return Arrays.asList("createBy","createTime","updateBy","updateTime","version","deleteFlag");
    }

    public static List<TypeMapping> getDefaultTypeMappings() {
        return Arrays.asList(
                // ========================  mysql ===========================================
                // TINYINT SMALLINT MEDIUMINT INT BIGINT bit
                new TypeMapping( DbType.MYSQL, "","bigint", "Long",true),
                new TypeMapping( DbType.MYSQL, "","int", "Integer",true),
                new TypeMapping( DbType.MYSQL, "","mediumint", "Integer",true),
                new TypeMapping( DbType.MYSQL, "","smallint", "Integer",true),
                new TypeMapping( DbType.MYSQL, "","tinyint", "Integer",true),
                new TypeMapping( DbType.MYSQL, "","bit", "Integer",true),

                // FLOAT DOUBLE DECIMAL
                new TypeMapping( DbType.MYSQL, "","float", "Float",true),
                new TypeMapping( DbType.MYSQL, "","double", "Double",true),
                new TypeMapping( DbType.MYSQL, "","decimal", "java.math.BigDecimal",true),

                // CHAR VARCHAR  TINYTEXT  TEXT  MEDIUMTEXT  LONGTEXT
                // TINYBLOB BLOB MEDIUMBLOB LONGBLOB
                new TypeMapping( DbType.MYSQL, "","char", "String",true),
                new TypeMapping( DbType.MYSQL, "","varchar", "String",true),
                new TypeMapping( DbType.MYSQL, "","tinytext", "String",true),
                new TypeMapping( DbType.MYSQL, "","text", "String",true),
                new TypeMapping( DbType.MYSQL, "","mediumtext", "String",true),
                new TypeMapping( DbType.MYSQL, "","longtext", "String",true),
                new TypeMapping( DbType.MYSQL, "","json", "String",true),

                // DATE TIME YEAR DATETIME TIMESTAMP
                new TypeMapping( DbType.MYSQL, "","date", "java.util.Date",true),
                new TypeMapping( DbType.MYSQL, "","time", "java.util.Date",true),
                new TypeMapping( DbType.MYSQL, "","datetime", "java.util.Date",true),
                new TypeMapping( DbType.MYSQL, "","timestamp", "java.util.Date",true),




                // ========================  oracle ===========================================
                new TypeMapping( DbType.ORACLE, "","integer", "Integer",true),
                new TypeMapping( DbType.ORACLE, "","float", "Double",true),
                new TypeMapping( DbType.ORACLE, "","binary_float", "Double",true),
                new TypeMapping( DbType.ORACLE, "","binary_double", "Double",true),
                new TypeMapping( DbType.ORACLE, "","real", "Double",true),
                new TypeMapping( DbType.ORACLE, "","number", "java.math.BigDecimal",true),
                new TypeMapping( DbType.ORACLE, "","decimal", "java.math.BigDecimal",true),

                // date timestamp
                new TypeMapping( DbType.ORACLE, "","date", "java.sql.Date",true),
                new TypeMapping( DbType.ORACLE, "","timestamp", "java.sql.Date",true),

                //CHAR VARCHAR  varchar2 TINYTEXT  TEXT  MEDIUMTEXT  LONGTEXT
                // TINYBLOB BLOB MEDIUMBLOB LONGBLOB
                new TypeMapping( DbType.ORACLE, "","char", "String",true),
                new TypeMapping( DbType.ORACLE, "","nchar", "String",true),
                new TypeMapping( DbType.ORACLE, "","varchar", "String",true),
                new TypeMapping( DbType.ORACLE, "","varchar2", "String",true),
                new TypeMapping( DbType.ORACLE, "","nvarchar2", "String",true),
                new TypeMapping( DbType.ORACLE, "","long", "String",true),
                new TypeMapping( DbType.ORACLE, "","tinytext", "String",true),
                new TypeMapping( DbType.ORACLE, "","text", "String",true),
                new TypeMapping( DbType.ORACLE, "","mediumtext", "String",true),
                new TypeMapping( DbType.ORACLE, "","longtext", "String",true),




                // ========================  postgre ===========================================
                // smallint integer bigint
                new TypeMapping( DbType.POSTGRE, "","bigint", "Long",true),
                new TypeMapping( DbType.POSTGRE, "","int8", "Long",true),
                new TypeMapping( DbType.POSTGRE, "","integer", "Integer",true),
                new TypeMapping( DbType.POSTGRE, "","int4", "Integer",true),
                new TypeMapping( DbType.POSTGRE, "","smallint", "Short",true),
                new TypeMapping( DbType.POSTGRE, "","int2", "Short",true),

                // smallserial serial bigserial
                new TypeMapping( DbType.POSTGRE, "","bigserial", "Long",true),
                new TypeMapping( DbType.POSTGRE, "","serial8", "Long",true),
                new TypeMapping( DbType.POSTGRE, "","serial", "Integer",true),
                new TypeMapping( DbType.POSTGRE, "","serial4", "Integer",true),
                new TypeMapping( DbType.POSTGRE, "","smallserial", "Integer",true),
                new TypeMapping( DbType.POSTGRE, "","serial2", "Integer",true),

                //decimal numeric real double
                new TypeMapping( DbType.POSTGRE, "","decimal", "java.math.BigDecimal",true),
                new TypeMapping( DbType.POSTGRE, "","numeric", "java.math.BigDecimal",true),
                new TypeMapping( DbType.POSTGRE, "","real", "Double",true),
                new TypeMapping( DbType.POSTGRE, "","double", "Double",true),
                new TypeMapping( DbType.POSTGRE, "","float4", "Double",true),
                new TypeMapping( DbType.POSTGRE, "","float8", "Double",true),


                //CHAR VARCHAR  TINYTEXT  TEXT  MEDIUMTEXT  LONGTEXT
                // TINYBLOB BLOB MEDIUMBLOB LONGBLOB
                new TypeMapping( DbType.POSTGRE, "","char", "String",true),
                new TypeMapping( DbType.POSTGRE, "","bpchar", "String",true),
                new TypeMapping( DbType.POSTGRE, "","varchar", "String",true),
                new TypeMapping( DbType.POSTGRE, "","tinytext", "String",true),
                new TypeMapping( DbType.POSTGRE, "","text", "String",true),
                new TypeMapping( DbType.POSTGRE, "","mediumtext", "String",true),
                new TypeMapping( DbType.POSTGRE, "","longtext", "String",true),

                new TypeMapping( DbType.POSTGRE, "","xml", "String",true),
                new TypeMapping( DbType.POSTGRE, "","json", "String",true),

                new TypeMapping( DbType.POSTGRE, "","geometry", "String",true),


                // boolean
                new TypeMapping( DbType.POSTGRE, "","bool", "Boolean",true),
                new TypeMapping( DbType.POSTGRE, "","boolean", "Boolean",true),


                //timestamp date time interval
                new TypeMapping( DbType.POSTGRE, "","date", "java.util.Date",true),
                new TypeMapping( DbType.POSTGRE, "","time", "java.util.Date",true),
                new TypeMapping( DbType.POSTGRE, "","timez", "java.util.Date",true),
                new TypeMapping( DbType.POSTGRE, "","datetime", "java.util.Date",true),
                new TypeMapping( DbType.POSTGRE, "","timestamp", "java.util.Date",true),
                new TypeMapping( DbType.POSTGRE, "","timestamptz", "java.util.Date",true)
        );
    }
}
